import pygame

# #启动pygame模块
# pygame.init()
#
# #制作窗口
# pygame.display.set_mode((500,500)) #前宽度后高度，返回值为surface对象
#
# #设置窗口标题
# pygame.display.set_caption(title='')
#
# #关闭
# pygame.QUIT

# 例
pygame.init()
aa = pygame.display.set_mode((500, 500))
pygame.display.set_caption('示例')
exit = False
while not exit:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit = True
    pygame.display.update()




# 添加图片，blit()
 # blit(src, dest)
# src : 它是我们要在屏幕上显示的图像的来源。
# dest : 它是我们希望显示图像的坐标。
import pygame

pygame.init()
# 改1
color = (255, 255, 255)
position = (0, 0)

aa = pygame.display.set_mode((500, 500))
pygame.display.set_caption('示例')
# 改2
image = pygame.image.load('p1_jump.png')

exit = False
while not exit:
    # 改3
    aa.fill(color)
    aa.blit(image, dest=position)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit = True
    pygame.display.update()




# 窗口中的矩形框
# rect()Pygame使用Rect对象来存储和操作矩形区域。
# 它可以由左、上、宽、高值的组合形成。
import pygame

pygame.init()

color = (255, 255, 255)
# 改
# position = (0, 0)
rect_color = (255, 0, 0)

aa = pygame.display.set_mode((500, 500))
pygame.display.set_caption('示例')

image = pygame.image.load('p1_jump.png')

exit = False
while not exit:

    aa.fill(color)
    # 改
    # aa.blit(image, dest=position)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit = True
    pygame.draw.rect(aa, rect_color, pygame.Rect(30, 30, 60, 60))
    pygame.display.update()












import time
import pygame
import random

# 创建游戏窗口大小
WIDTH = 360
HEIGHT = 480
FPS = 40
# Colors(R,G,B)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)


# 精灵
class Player(pygame.sprite.Sprite):
    # sprite for the player
    def __init__(self):
        # this line is required to properly create the sprite
        pygame.sprite.Sprite.__init__(self)
        # creat a plain rectangle for the sprite image
        self.image = pygame.Surface((50, 50))
        self.image.fill(GREEN)
        #find the rectangle that encloses the image
        self.rect=self.image.get_rect()
        #center the sprite on the screen
        self.rect.center=(WIDTH/2,HEIGHT/2)
    def update(self):
        # any code here will happen every time the game loop updates
        self.rect.x+=3
        if self.rect.left>WIDTH:
            self.rect.right=0

# creat window
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("MY Game")
clock = pygame.time.Clock()

myfont = pygame.font.Font(None, 60)
textImage = myfont.render('pygame', True, WHITE)
# game loop
running = True
count = 0
start = time.time()
while running:
    # keep right speed
    clock.tick(FPS)
    # input
    for event in pygame.event.get():
        # check for closing window
        if event.type == pygame.QUIT:
            running = False
    # update
    count += 1
    now = time.time()
    fps = count / (now - start)
    fpsImage = myfont.render(str(fps), True, WHITE)
    # draw/render
    screen.fill(BLACK)
    screen.blit(fpsImage, (10, 100))
    pygame.display.flip()
pygame.quit







import pygame
import random
import os

WIDTH = 900
HEIGHT = 600
FPS = 30

#colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)

# set up assets folders

game_folder = os.path.dirname(__file__)
img_folder = os.path.join(game_folder, "学习记录")


class Player(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load(os.path.join(img_folder, "p1_jump.png")).convert()
        self.image.set_colorkey(BLACK)
        self.rect = self.image.get_rect()
        self.rect.center = (WIDTH / 2, HEIGHT / 2)
        self.y_speed = 5

    def update(self):
        self.rect.x += 3
        self.rect.y += self.y_speed
        if self.rect.bottom > HEIGHT - 200:
            self.y_speed = -5
        if self.rect.top < 200:
            self.y_speed = 3
        if self.rect.left > WIDTH:
            self.rect.right = 0


# initialize pygame and create window
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("My Game")
clock = pygame.time.Clock()

all_sprites = pygame.sprite.Group()
player = Player()
all_sprites.add(player)
# Game loop
running = True
while running:
    # keep loop running at the right speed
    clock.tick(FPS)
    # Process input (events)
    for event in pygame.event.get():
        # check for closing window
        if event.type == pygame.QUIT:
            running = False







import pygame
import random

WIDTH = 800
HEIGHT = 600
FPS = 30

# colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)


class Player(pygame.sprite.Sprite):
    # sprite for the Player
    def __init__(self):
        # this line is required to properly create the sprite
        pygame.sprite.Sprite.__init__(self)
        # create a plain rectangle for the sprite image
        self.image = pygame.Surface((50, 50))
        self.image.fill(GREEN)
        # find the rectangle that encloses the image
        self.rect = self.image.get_rect()
        # center the sprite on the screen
        self.rect.center = (WIDTH / 2, HEIGHT / 2)

    def update(self):
        self.rect.x += 5
        if self.rect.left > WIDTH:
            self.rect.right = 0


# create window
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Sprite Example")
clock = pygame.time.Clock()

all_sprites = pygame.sprite.Group()
player = Player()
all_sprites.add(player)
# Game loop
running = True
while running:
    # keep loop running at the right speed
    clock.tick(FPS)
    # Process input (events)
    for event in pygame.event.get():
        # check for closing window
        if event.type == pygame.QUIT:
            running = False

    # Update
    all_sprites.update()
    screen.fill(BLACK)
    all_sprites.draw(screen)
    pygame.display.flip()

pygame.quit()